import React, { useState } from 'react'
import LoginPng from "../../assict/images/登录.png"
import { TeamOutlined, UnlockOutlined } from '@ant-design/icons';
import { message } from "antd"
import { request, history } from 'umi';
import { encrypt } from "./encrypts"
import "../login/index.less"



export default function index() {
    let [user, setUser] = useState("")
    let [pass, setPass] = useState("")
    const use = (e: any) => {
        setUser(e.target.value)
    }
    const pas = (e: any) => {
        setPass(e.target.value)
    }
    const login = () => {
        if (user == "" && pass == "") {
            message.error("请输入账号或者密码");
            return
        }
        request("/campus/campusweb/ipuser/login", {
            method: "post",
            data: {
                userAccount: "18979307261",
                userPwd: encrypt("zhhdzs129")
            }
        })
            .then(res => {
                if (res.code == 200) {
                    window.localStorage.setItem("isLogin", JSON.stringify({
                        userAccount: "18979307261",
                        userPwd: "zhhdzs129"
                    }))
                    history.push("/lotteryWhiteList")
                    message.success('登录成功');
                } else {
                    message.error(res.message);
                }
            })
    }
    return (
        <div>
            <div className='login'>
                <img src={LoginPng} alt="" />
                <div className='loginDiv'>
                    <h1>秦学后台管理</h1>
                    <div> <TeamOutlined /><input onChange={use} type="text" /></div>
                    <div> <UnlockOutlined /><input onChange={pas} type="password" /></div>
                    <div style={{ backgroundColor: '#1A267B', color: "#fff", marginTop: "62px" }} onClick={login}><button>登陆</button></div>
                    <p>使用手机小程序提示的账号密码登录</p>
                </div>
            </div>
        </div>
    )
}
